import 'package:flutter/material.dart';
import 'model/post.dart';


void main() => runApp(App());

// StatelessWidget StatefulWidget
class App extends StatelessWidget {
  // StatelessWidget 不需要修改小部件
  // StatefulWidget 需要修改小部件

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      home: Home(),
      theme: ThemeData(
        // 设置导航栏主题颜色
        primarySwatch: Colors.red,
      ),
    );
  }
}


class Home extends StatelessWidget {

  Widget _listItemBuilder(BuildContext context, int index) {
//    return Text(posts[index].title);
    return Container(
      color: Colors.white,
      margin: EdgeInsets.all(8.0),
      child: Column(
        children: <Widget>[
          Image.network(posts[index].imageUrl),
          SizedBox(height: 16.0),
          Text(
            posts[index].title,
            style: Theme.of(context).textTheme.title,
          ),
          Text(
            posts[index].author,
            style: Theme.of(context).textTheme.subhead,
          ),
          SizedBox(height: 16.0),
        ],
      ),
    );
  }
  

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      backgroundColor: Colors.grey[100],
      appBar: AppBar(
        // 设置标题
        title: Text('Fultter 学习'),
        // 设置阴影
        elevation: 30.0,
      ),

      body: ListView.builder(
        itemCount: posts.length,
        itemBuilder: _listItemBuilder,
      ),
//      body: Hello(),

    );
  }
}

class Hello extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    return Center (
      child: Text(
        'Hello World',
        textDirection: TextDirection.ltr,
        style: TextStyle(
          fontSize: 40.0,
          fontWeight: FontWeight.bold,
          color: Colors.black,
        ),
      ),
    );
  }
}
